/*
 * communication_plugin.h
 *
 *  Created on: Apr 26, 2017
 *      Author: zeroun
 */

#ifndef COMMUNICATION_PLUGIN_H_
#define COMMUNICATION_PLUGIN_H_

#pragma once

#include <map>
#include "augmavconn/augmavconn.h"
//#include <mavconn/interface.h>
#include <ros/ros.h>

namespace commplugin {

#define PACK_CHAN(link)			\
        link->get_system_id(),		\
        link->get_component_id(),		\
        link->get_channel()

typedef std::lock_guard<std::recursive_mutex> lock_guard;
typedef std::unique_lock<std::recursive_mutex> unique_lock;

/**
 * @brief Helper macros to define message handler map item
 */
#define MESSAGE_HANDLER(_message_id, _class_method_ptr)	\
	{ _message_id, boost::bind(_class_method_ptr, this, _1, _2, _3) }

/**
 * @brief MAVROS Plugin base class
 */
class CommPlugin
{
private:
	CommPlugin(const CommPlugin&) = delete;

public:
	typedef boost::function<void (const mavlink_message_t *msg, uint8_t sysid, uint8_t compid)> message_handler;
	typedef std::map<uint8_t, message_handler> message_map;
	// pluginlib return boost::shared_ptr
	typedef boost::shared_ptr<CommPlugin> Ptr;
	typedef boost::shared_ptr<CommPlugin const> ConstPtr;

	virtual ~CommPlugin() {};

	/**
	 * @brief Plugin initializer
	 *
	 * @param[in] uas           UAS instance (handles FCU connection and some statuses)
	 */
        virtual void initialize(augmavconn::AugMavConnInterface::AugPtr station_link, int target_system_id, int target_component_id) = 0;

	/**
	 * @brief Return map with message rx handlers
	 */
	virtual const message_map get_rx_handlers() = 0;

protected:
	/**
	 * @brief Plugin constructor
	 * Should not do anything before initialize()
	 */
	CommPlugin() {};
};
};	// namespace mavplugin



#endif /* COMMUNICATION_PLUGIN_H_ */
